package com.emit.security.resultReturned;

import com.alibaba.fastjson.JSON;
import com.emit.security.ResultCode;
import com.emit.utils.Constant;
import com.emit.view.ResultView;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author zhengshuai
 * @date 2021/5/25
 * @Description: 登出成功处理逻辑
 */
@Component
public class CustomizeLogoutSuccessHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        ResultView result =new ResultView( ResultCode.SUCCESS);
        httpServletResponse.setContentType(Constant.CONTENT_TYPE);
        httpServletResponse.getWriter().write(JSON.toJSONString(result));
    }
}

